<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>员工管理</title>

    <link href="../plugin/bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-table-1.11.1/bootstrap-table.min.css" rel="stylesheet"/>
    <link href="../plugin/sweetalert-6.6.2/sweetalert2.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-3.3.7/plugin/file_input/fileinput.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
    <link href="../plugin/jquery-zoomify/zoomify.min.css" rel="stylesheet"/>
    <link href="../plugin/jstree/jstree.min.css" rel="stylesheet">

    <script src="../plugin/jquery-3.2.1/jquery-3.2.1.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/file_input/fileinput.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/file_input/local_zh.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/bootstrap-table.min.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="../plugin/sweetalert-6.6.2/sweetalert2.min.js"></script>
    <script src="../plugin/jquery-3.2.1/jquery.formautofill.min.js"></script>
    <script src="../plugin/jquery-zoomify/zoomify.min.js"></script>
    <script src="../plugin/jquery-3.2.1/jquery.serializejson.js"></script>
    <script src="../plugin/soul/utils3.js"></script>
    <script src='../base/base.js'></script>
    <script src="../plugin/jstree/jstree.min.js"></script>

</head>

<body>
<div class="modal fade" data-backdrop="static" id="staff_manager_privilege_edit_modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
                <h4 class="modal-title">
                    <b>用户权限编辑</b>
                </h4>
            </div>
            <div class="modal-body">
                <form id="staff_manager_privilege_edit_form" method="post">
                    <div class="form-group">
                        <label>权限列表</label>
                        <div id="staff_manager_privilege_edit_form_privIds"></div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">取消</button>
                <button class="btn btn-primary" onclick="staff_manager.privilege.save()">保存</button>
            </div>
        </div>
    </div>
</div>


<div class="modal fade" data-backdrop="static" id="staff_manager_modal_edit_detail">
    <div class="modal-dialog modal-lg ">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
                <h4 class="modal-title">
                    <b>用户资质</b>
                </h4>
            </div>
            <div class="modal-body">
                <div id="staff_manager_modal_edit_detail_editor"></div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">取消</button>
                <button class="btn btn-primary" onclick="staff_manager.detail.save()">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    $(function () {
        var resp = AjaxUtil.isLogin();
        if (!resp) return;
        var module = 'staff_manager';
        var query = [{
            id: 'realname',
            type: 'text',
            name: '姓名',
            paramName: 'realname',
            palceholder: ''
        }, {
            id: 'phone',
            type: 'text',
            name: '电话号码',
            paramName: 'phone',
            palceholder: ''
        }, {
            id: 'username',
            type: 'text',
            name: '用户名',
            paramName: 'username',
            palceholder: ''
        }, {
            id: 'idNum',
            type: 'text',
            name: '身份证号码',
            paramName: 'idNum',
            palceholder: ''
        }];
        var toolbar = {
            default: [false, true, true, true],// back;add;edit;remove
            dialog: [60, 2, 9],//对话框参数:模态框宽度(百分比);表单标题宽度;表单输入框宽度
            extra: [
                   {
                        name: '编辑用户权限',
                        onclick: 'showStaffPrivilegeModal'
                     }
                // , {
                //     name: '重置密码',
                //     onclick: 'resetPassword'
                // }
                // {
                //     name: '用户资质',
                //     glyphicon: 'list',
                //     onclick: 'showQualification',
                // }
            ]
        };
        var formElement = [{
            action: [false, true],
            type: 'hidden',
            name: 'staffId',
        }, {
            action: [true, true],
            type: 'text',
            label: '用户名',
            name: 'username',
        }, {
            action: [true, true],
            type: 'text',
            label: '电话号码',
            name: 'phone',
        }, {
            action: [true, true],
            type: 'text',
            label: '真实姓名',
            name: 'realname',
        }, {
            action: [true, true],
            id: 'roleId',
            type: 'select',
            label: '角色',
            name: 'roleId',
            items: 'staff/selectItem'
        }];
        var bootstrapTable = {
            columns: [{
                radio: true
            }, {
                field: 'staffId',
                title: '员工ID',
            }, {
                field: 'username',
                title: '用户名',
            }, {
                field: 'phone',
                title: '电话号码',
            }, {
                field: 'roleName',
                title: '角色',
            }, {
                field: 'privJson',
                title: '后台权限明细',
                align: 'center',
                formatter: function (value, row, index) {
                    var priv = '';
                    if (''== value) {
                        return  priv = "无";
                    }
                    var privJson = JSON.parse(value);

                    for (i in privJson) {
                        if (privJson[i].parentId == null) {
                            priv += privJson[i].name + ','
                        }
                    }
                    if (priv.length > 0) {
                        priv = priv.substring(0, priv.length - 1);
                    } else {
                        priv = '无';
                    }
                    return priv;
                }
            }]
        };
        staff_manager = SingleTablePageCreateUtil.createInstance(module, query, toolbar, formElement, bootstrapTable);
        staff_manager.privilege = {};
        staff_manager.showStaffPrivilegeModal = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#staff_manager_table');
            if (!row) return false;
            staff_manager.privilege.currentStaffId = row.staffId;
            var resp = AjaxUtil.getJson('privilege/list');
            if (!resp) return false;
            var jsTreeData = JsTreeUtil.createPrivTree('#staff_manager_privilege_edit_form_privIds', resp.obj, row.privIds);
            $('#staff_manager_privilege_edit_modal').modal('show');
        };
        staff_manager.privilege.save = function () {
            var staffPrivIds = JsTreeUtil.getCheck('#staff_manager_privilege_edit_form_privIds');
            var resp = AjaxUtil.postJson('staff_manager/edit_priv', {
                staffId: staff_manager.privilege.currentStaffId,
                privIds: staffPrivIds
            });
            if (resp) {
                SwalUtil.success(resp.msg);
                $('#staff_manager_table').bootstrapTable('refresh');
                $('#staff_manager_privilege_edit_modal').modal('hide');
            }
        };
        staff_manager.onEditModalShowBefore = function (row) {
            row.createDate = FormatUtil.formatDateTime(row.createDate);
            return row;
        };
        staff_manager.onRemoveSubmitBefore = function (row) {
            row.createDate = FormatUtil.formatDateTime(row.createDate);
            return row;
        };
        staff_manager.resetPassword = function (row) {
            var row = TablePageCreatePublicUtil.getRowFromTable('#staff_manager_table');
            row.createDate = '';
            var resp = AjaxUtil.postJson("staff_manager/resetPassword", row);
            SwalUtil.success(resp.msg);
        }


        staff_manager.showQualification = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#staff_manager_table');
            if (!row) return false;
            staff_manager.detail.currentId = row.staffId;
            editor.txt.html(row.qualification || '');
            $('.w-e-text-container').css('height', '500px')
            $('#staff_manager_modal_edit_detail').modal('show');
        };


        staff_manager.detail = {};
        staff_manager.detail.currentId = undefined;
        staff_manager.detail.save = function () {
            var qualification = editor.txt.html();
            console.log(qualification);
            var resp = AjaxUtil.postJson('staff_manager/editQualification', {
                staffId: staff_manager.detail.currentId,
                qualification: qualification
            });
            if (resp) {
                SwalUtil.success(resp.msg);
                $('#staff_manager_table').bootstrapTable('refresh');
                $('#staff_manager_modal_edit_detail').modal('hide');
                editor.txt.html('');
            }

        };

        var E = window.wangEditor;
        var editor = new E('#staff_manager_modal_edit_detail_editor');
        editor.customConfig.uploadImgServer = '/wangEditor/uploadImages?token=' + BaseConfig.token;
        editor.customConfig.uploadFileName = 'file';
        // editor.customConfig.uploadImgMaxLength = 1;
        editor.customConfig.uploadImgTimeout = 3 * 60 * 1000;
        editor.create();
    });
</script>
</html>